package com.zlict.admin.service.impl;

import com.zlict.admin.domain.ProjectMember;
import com.zlict.admin.mapper.ProjectMemberMapper;
import com.zlict.admin.service.IProjectMemberService;
import com.zlict.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

import static com.zlict.common.utils.SecurityUtils.getUserId;

/**
 * 项目人员Service业务层处理
 * 
 * @author dzw
 * @date 2025-06-10
 */
@Service
public class ProjectMemberServiceImpl implements IProjectMemberService
{
    @Autowired
    private ProjectMemberMapper projectMemberMapper;

    /**
     * 查询项目人员
     * 
     * @param id 项目人员主键
     * @return 项目人员
     */
    @Override
    public ProjectMember selectProjectMemberById(Long id)
    {
        return projectMemberMapper.selectProjectMemberById(id);
    }

    /**
     * 查询项目人员列表
     * 
     * @param projectMember 项目人员
     * @return 项目人员
     */
    @Override
    public List<ProjectMember> selectProjectMemberList(ProjectMember projectMember)
    {
        projectMember.setIsDelete(false);
        projectMember.setIsEnable(true);
        return projectMemberMapper.selectProjectMemberList(projectMember);
    }

    /**
     * 新增项目人员
     * 
     * @param projectMember 项目人员
     * @return 结果
     */
    @Override
    public int insertProjectMember(ProjectMember projectMember)
    {
        projectMember.setCreateTime(DateUtils.getNowDate());
        projectMember.setCreateBy(getUserId());
        return projectMemberMapper.insertProjectMember(projectMember);
    }
    /**
     * 批量新增项目人员
     *
     * @param projectMember 项目人员
     * @return 结果
     */
    @Override
    public int insertProjectMembers(ProjectMember projectMember)
    {
        Date nowDate = DateUtils.getNowDate();
        return projectMemberMapper.insertProjectMembers(projectMember.getProjectId(),projectMember.getUserIds(),nowDate,getUserId());
    }

    /**
     * 修改项目人员
     * 
     * @param projectMember 项目人员
     * @return 结果
     */
    @Override
    public int updateProjectMember(ProjectMember projectMember)
    {
        projectMember.setUpdateTime(DateUtils.getNowDate());
        projectMember.setUpdateBy(getUserId());
        return projectMemberMapper.updateProjectMember(projectMember);
    }

    /**
     * 批量删除项目人员
     * 
     * @param ids 需要删除的项目人员主键
     * @return 结果
     */
    @Override
    public int deleteProjectMemberByIds(Long[] ids)
    {
        return projectMemberMapper.deleteProjectMemberByIds(ids);
    }

    /**
     * 删除项目人员信息
     * 
     * @param id 项目人员主键
     * @return 结果
     */
    @Override
    public int deleteProjectMemberById(Long id)
    {
        return projectMemberMapper.deleteProjectMemberById(id);
    }


}
